﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL.ManageDBLNo
{
    class GenerateCode
    {
        /// <summary>
        /// 生成正反连续的数字序列
        /// </summary>
        /// <param name="length">生成数字序列的长度</param>
        /// <param name="isBoth">true从小到大和从大到小，false从小到大</param>
        /// <param name="totalLength">字符串总长度</param>
        /// <returns></returns>
        //public List<string> GenerateSequenceCode(int length, int totalLength, bool isBoth)
        //{
        //    if (length > totalLength)
        //    {
        //        throw new ApplicationException("生成数字序列的长度不能大于数字总长度");
        //    }
        //    if (length <= 1)
        //    {
        //        throw new ApplicationException("不能产生小于等于1的数字序列");
        //    }

            
        //    string maxnum = string.Empty;
        //    string minnum = string.Empty;
        //    for (int i = 0; i < totalLength; i++)
        //    {
        //        maxnum = maxnum + "9";
        //        minnum = minnum + "0";
        //    }

        //    for (int j = Int32.Parse(minnum); j < Int32.Parse(maxnum); j++)
        //    {
        //        string s = j.ToString();
        //    }
        //}
        /// <summary>
        /// 生成同号
        /// length = 4 0000 1111 2222 。。。 9999
        /// </summary>
        /// <param name="length">同号长度</param>
        /// <param name="totalLenght">总长度</param>
        /// <returns></returns>
        public static List<string> GenerateRepeatCode(int length)
        {
            List<string> list = new List<string>();
            for (int i = 0; i <= 9; i++)
            {
                StringBuilder sb = new StringBuilder();
                for (int j = 1; j <= length; j++)
                {
                    sb.Append(i);
                }
                list.Add(sb.ToString());
            }
            return list;
        }
        
        
        /// <summary>
        /// 生成连号
        /// </summary>
        /// <param name="lenght"></param>
        /// <param name="isBoth"></param>
        /// <returns></returns>
        public static List<string> GenerateSequenceCode(int lenght,bool isBoth/*是否生成正反双向序列*/)
        {
            List<string> list = new List<string>();
            for (int i = 1; i <= 10-lenght; i++)
            {
                string s =string.Empty;
                for (int j = i; j < i+lenght; j++)
                {
                    s = s + j;
                }
                list.Add(s);
            }

            List<string> reverseList = new List<string>();
            if (isBoth)
            {
                foreach (string s in list)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = s.Length - 1; i >= 0; i--)
                    {
                        sb.Append(s[i]);//字符串翻转
                    }
                    reverseList.Add(sb.ToString());
                }
            }
            list.AddRange(reverseList);
            return list;
        }

        /// <summary>
        /// 根据输入字符串的格式生成code
        /// </summary>
        /// <param name="pattern"></param>
        /// <returns></returns>
        //public List<string> GeneratePatternCode(string pattern)
    }
}
